package cn.hfatec.shms.advice;

import cn.hfatec.dataSource.DataSourceHolder;
import cn.hfatec.shms.advice.annotation.*;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author: panwb
 *
 * Date: 2016/8/5
 * Time: 14:54
 */
@Aspect
@Component
@Order(-1)
public class DataSourceAdvice {

    @Pointcut(value = "@annotation(mysqlDataSource)", argNames = "mysqlDataSource")
    public void setMysqlDataSource(MysqlDataSource mysqlDataSource) {
    }
    @Pointcut(value = "@annotation(mysqlDataSourceXm)", argNames = "mysqlDataSourceXm")
    public void setMysqlDataSourceXm(MysqlDataSourceXm mysqlDataSourceXm) {
    }
    @Pointcut(value = "@annotation(mysqlDataSourceOA)", argNames = "mysqlDataSourceOA")
    public void setMysqlDataSourceOA(MysqlDataSourceOA mysqlDataSourceOA) {
    }

    @Pointcut(value = "@annotation(oracleDataSource)", argNames = "oracleDataSource")
    public void setOracheDataSource(OracleDataSource oracleDataSource) {
    }

    @Pointcut(value = "@annotation(sqlServerDataSource)", argNames = "sqlServerDataSource")
    public void setSqlServerDataSource(SqlServerSource sqlServerDataSource) {
    }

    @Before(value = "setMysqlDataSource(mysqlDataSource)")
    public void beforeMysql(JoinPoint joinPoint, MysqlDataSource mysqlDataSource) {
        DataSourceHolder.setDataSource("mysqlDataSource");
    }
    @Before(value = "setMysqlDataSourceXm(mysqlDataSourceXm)")
    public void beforeMysqlXm(JoinPoint joinPoint, MysqlDataSourceXm mysqlDataSourceXm) {
        DataSourceHolder.setDataSource("mysqlDataSourceXm");
    }
    @Before(value = "setMysqlDataSourceOA(mysqlDataSourceOA)")
    public void beforeMysqlOA(JoinPoint joinPoint, MysqlDataSourceOA mysqlDataSourceOA) {
        DataSourceHolder.setDataSource("mysqlDataSourceOA");
    }
    @Before(value = "setOracheDataSource(oracleDataSource)")
    public void beforeOracle(JoinPoint joinPoint, OracleDataSource oracleDataSource) {
        DataSourceHolder.setDataSource("oracleDataSource");
    }

    @Before(value = "setSqlServerDataSource(sqlServerSource)")
    public void beforeSqlServer(JoinPoint joinPoint, SqlServerSource sqlServerSource) {
        DataSourceHolder.setDataSource("sqlServerDataSource");
    }
}
